import numpy as np

# 生成简单数据
X = np.array([1, 2, 3, 4, 5])
y = np.array([2, 4, 6, 8, 10])

# 计算回归系数
# y = w * X + b
w = ((X - X.mean()) * (y - y.mean())).sum() / ((X - X.mean())**2).sum()
b = y.mean() - w * X.mean()

print(f"w: {w}, b: {b}")

# 预测
def predict(x):
    return w * x + b

print(predict(6))  # 预测x=6时的y值